#include "WorldGeometry.h"
#include "Point2.h"
#include "IoPoint2.h"
#include "Vector2.h"
#include "IoVector2.h"
#include <iostream>

namespace Tests {
	void world() {
		WorldGeometry world; {
			const double q = 1.5;
			Point2 outerContour[] = {
				Point2( -q, -q ),
				Point2(  q, -q ),
				Point2(  q,  q ),
				Point2( -q,  q )
			};

			const double h = .5;
			const double p = 1;
			Point2 innerContour[] = {
				Point2( -p,  p ),
				Point2(  0,  p ),
				Point2(  0,  0 ),
				Point2(  p,  0 ),
				Point2(  p, -p ),
				Point2( -p, -p )
			};

			Contour2 c[] = {
				Contour2( outerContour, outerContour + sizeof(outerContour)/sizeof(outerContour[0]) ),
				Contour2( innerContour, innerContour + sizeof(innerContour)/sizeof(innerContour[0]) )
			};

			Polygon2 poly( c, c + sizeof(c)/sizeof(c[0]) );
			world.compile( &poly, 1 );
		}

		Point2 pt = Point2( -.5, .75 );
		Vector2 dir = Vector2( 1, -1 );
		Vector2 n;
		Point2 newPt;

		WorldGeometry::IntersectionResult result;
		int idx = 0;
		for ( ; idx < 7; idx++ ) {
			std::cout << '#' << idx << ": pt=" << pt << " dir=" << dir << std::endl;
			if ( world.trace( pt, dir, result ) ) {
				dir = dir.reflected( result.normal );
				pt = result.intersection;
			} else {
				std::cout << "No intersection" << std::endl;
				break;
			}
		}
		std::cout << '#' << idx << ": pt=" << pt << " dir=" << dir << std::endl;
	}
}
